package com.kehutong.charge.admin;

import com.kehutong.charge.dto.MessageTempDTO;
import com.kehutong.charge.entity.ChargeOrderManage;
import com.kehutong.charge.service.ChargeOrderService;
import com.kehutong.charge.service.CommonService;
import com.kehutong.charge.util.enums.ChargeBillStatusEnum;
import com.kehutong.charge.util.enums.UrgingTypeEnum;
import com.kehutong.common.urlconfig.WebUrlConfig;
import com.kehutong.common.util.Token;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @program: kht
 * @description: 下拉组件调用接口
 * @author: joneron
 * @create: 2021/7/12
 **/
@MvcAction
@ReqMapping("/admin/pay/charge/common")
public class CommonController {

    private static final Logger logger = LoggerFactory.getLogger(CommonController.class);

    @Inject
    CommonService commonService;

    @Inject
    private WebUrlConfig webUrlConfig;

    @Inject
    ChargeOrderService chargeOrderService;

    @ReqMapping("/findFeeConfigList")
    public Object feeList(JSONObject jsonObject) {
        return commonService.findFeeConfigList(jsonObject);
    }

    /**
     * 日志列表
     * @return
     */
    @ReqMapping("/findLoggerPage")
    public Object logList(JSONObject jsonObject) {
        return commonService.findLoggerList(jsonObject);
    }

    /**
     * 日志列表导出excel
     * @param jsonObject
     * @return
     */
    @ReqMapping("/findLogger/export")
    public void pageExport(HttpServletRequest req, HttpServletResponse resp, JSONObject jsonObject){
        commonService.pageExport(req,resp,jsonObject);
    }

    /**
     * 修改字典
     */
    @ReqMapping("/updateDict")
    public Object updateDict(JSONObject jsonObject){

        return commonService.updateDict(jsonObject);
    }

    /**
     * 查询定时配置
     */
    @ReqMapping("/findDict")
    public Object findDict(JSONObject jsonObject){

        return commonService.findDict(jsonObject);
    }

    /**
     * 消息模板 集合
     * @return
     */
    @ReqMapping("/getMessageTemp")
    public Object getMessageTemp() {

        List<Object> list = new ArrayList<>();
        MessageTempDTO me = new MessageTempDTO();
        me.setMessage("感谢您的订购，您的订单已经提交成功，订单号：$OrderId$。");
        me.setId("23232323");
        me.setName("订单消息");
        list.add(me);
        MessageTempDTO me2 = new MessageTempDTO();
        me2.setMessage("本期账单已出账，请及时处理，账单编号：$OrderId$。");
        me2.setId("787989");
        me2.setName("账单消息");
        list.add(me2);

        return Result.success(list);
    }



    /**
     * 催费类型枚举 集合
     * @return
     */
    @ReqMapping("/getUrgingTypeEnum")
    public Object getUrgingTypeEnum() {

        HashMap<String,String> maps = UrgingTypeEnum.getMap();

        return Result.success(maps);
    }

    /**
     * 缴费状态枚举 集合
     * @return
     */
    @ReqMapping("/getChargeStatusEnum")
    public Object getChargeStatusEnum() {

        HashMap<String,String> maps = ChargeBillStatusEnum.getMap();

        return Result.success(maps);
    }

    /**
     * 动态生成仪表数据
     * @return
     */
    @ReqMapping("/synMeterData")
    public Object synMeterData() {

        return Result.success(commonService.addMeterDataTask());
    }

    /**
     * 返回二维码路径
     * @param token
     * @param jsonObject
     * @return
     */
    @ReqMapping("/QRUrl")
    public String download(Token token, JSONObject jsonObject) {
        //返回应付订单金额
        final ChargeOrderManage chargeSundry = chargeOrderService.findOrderDetail(jsonObject);

        StringBuffer url = new StringBuffer()
                .append(webUrlConfig.getUrl("/pay/sundry/"))
                .append("?id=").append(chargeSundry.getOrderNo())
                .append("&companyNo=").append(token.getCompanyNo());

        return url.toString();
    }

}
